import java.util.LinkedList;

public class CustomUnit extends Thread {
	int id;
	int waitTime;

	LinkedList<Passenger> queue = new LinkedList<Passenger>();

	public CustomUnit(int id,int waitTime) {
		this.id = id;
		this.waitTime= waitTime;
	}
	public void update(int n){
		
		
		synchronized (this) {

			this.notify();

		}		Launch.textArea3.get(this.id-1).validate();
		
		Launch.textArea3.get(this.id-1).setText("Queue Length : " + this.queue.size()+"\n"+"Waiting Time : " + this.queue.size()*this.waitTime/1000 + " Min");

	}

	public void run() {
		while (true) {

			if (this.queue.size() == 0) {
				try {
					synchronized (this) {

						this.wait(1);

					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
			
			
			if (this.queue.size() > 0) {
				try {
					synchronized (this) {
						if (this.queue.size() > 0)
						this.queue.remove(0);
						this.update(this.queue.size());

						Launch.textArea3.get(this.id-1).validate();

						
						this.wait(waitTime);

					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				

			

			}

			
				synchronized (this) {
					this.notify();
				}
			
		}
	}
}
